package com.ibm.cloud.banking;

import com.alibaba.fastjson.JSONObject;
import com.alipay.sofa.rpc.ldc.LdcProviderManager;
import com.alipay.sofa.runtime.api.annotation.SofaReference;
import com.alipay.sofa.runtime.api.annotation.SofaReferenceBinding;
import com.ibm.cloud.banking.facade.main.PcsFacade;
import com.ibm.cloud.banking.generator.SleuthIdGenerator;

import com.ibm.cloud.banking.ldc.PocLdcRouterProvider;
import com.ibm.cloud.banking.platform.message.Request;
import com.ibm.cloud.banking.platform.message.RequestHeader;
import org.springframework.beans.BeansException;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.Bean;

import java.util.LinkedHashMap;
import java.util.Map;


@SpringBootApplication
//@EnableDiscoveryClient
public class OnlineEngineApplication implements ApplicationContextAware {
    private static ApplicationContext applicationContext1;


    public static void main(String[] args) {
//        System.setProperty("user.home","//D:/sofaRegistry");
//        LdcProviderManager.getInstance().registeLdcRouteProvider(new PocLdcRouterProvider());
        SpringApplication.run(OnlineEngineApplication.class, args);
//        Request request =new Request();
//        RequestHeader header= new RequestHeader();
//        header.setOtsCod("T22");
//        header.setReqGlbSerNo("12100110066");
//        header.setReqMsgTyp("1");
//        header.setDstSysCod("SYS01");
//        header.setMapElm1("01:6217991001000000580");
//        header.setMapElm2("02:22000000156");
//        header.setMsgLength("22");
//        header.setReqDate("20200216");
//        header.setInitChnCod("001");
//        header.setReqSysSerNo("123519");
//        header.setReqTrSerNo("111116");
//        header.setReqSysCod("1234");
//        header.setBnkGlDate("20200613");
//        header.setReqDate("1912094223888");
//        header.setDynLockFlg(0);
//        request.setReqHeader(header);
//        Map<String,String> map= new LinkedHashMap<>();
//        map.put("cardNo","6227190103000000001");
//        request.setReqBody(map);
//        PcsFacade pcsFacade=   applicationContext1.getBean(PcsFacade.class);
//        String s= JSONObject.toJSONString( pcsFacade.service(request));
//        System.out.println(s);
    }

    // todo remove to configurations
    @Bean
    public SleuthIdGenerator sleuthIdGenerator() {
        return new SleuthIdGenerator();
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext1=applicationContext;
    }
}
